#region

using System;
using System.Collections.Generic;
using System.Linq;
using Class.Web.Mvc;
using ThuySan.Bussiness;

#endregion

namespace ThuySan.Repository
{
    public partial class ProductRepository
    {
        #region IProductRepository Members

        public bool CheckDeleteProduct(List<int> list)
        {
            return true;
        }

        public bool CheckInsertProduct(Product product)
        {
            return true;
        }

        public bool CheckUpdateProduct(Product product)
        {
            return true;
        }

        public void Delete(IEnumerable<int> enumerable, string uploadPath, Action<string, string, IImageContent> func)
        {
            List<Product> products = Select(c => enumerable.Contains(c.ProductId), "Images,ProductPropertys").ToList();
            foreach (Product product in products)
            {
                if (!string.IsNullOrEmpty(product.AvatarImage))
                {
                    func.Invoke(uploadPath, product.AvatarImage, product);
                }
                while (product.Images.Count > 0)
                {
                    Image img = product.Images.First();
                    func.Invoke(uploadPath, img.ImageName, img);
                    product.Images.Remove(img);
                }
                // delete property
                while (product.ProductPropertys.Count > 0)
                {
                    var temp = product.ProductPropertys.First();
                    product.ProductPropertys.Remove(temp);
                    MarkAsDeleted(temp);
                }
            }
            Delete(products);
        }

        #endregion
    }
}
